package com.db.williamchart.renderer.executor;

import com.db.williamchart.data.DataPoint;
import com.db.williamchart.data.Frame;

import java.util.ArrayList;
import java.util.List;

public class GetHorizontalBarBackgroundFrames {

    public List<Frame> invoke(Frame innerFrame, Float spacingBetweenBars, List<DataPoint> data){
        float halfBarWidth =
                (innerFrame.getBottom() - innerFrame.getTop() - (data.size() + 1) * spacingBetweenBars) /
                        data.size() / 2;

        List<Frame> frames = new ArrayList<>();

        for (DataPoint dataPoint : data){
            frames.add(new Frame(innerFrame.getLeft(),dataPoint.getScreenPositionY() - halfBarWidth, innerFrame.getRight(), dataPoint.getScreenPositionY() + halfBarWidth));
        }

        return frames;
    }
}
